<?php

namespace app\admin\model;

use think\Model;

class Member extends Model
{
    // 表名
    protected $name = 'member';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'identity_text'
    ];
    

    
    public function getIdentityList()
    {
        return ['1' => __('Identity 1'),'2' => __('Identity 2'),'3' => __('Identity 3'),'4' => __('Identity 4'),'5' => __('Identity 5')];
    }     


    public function getIdentityTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['identity']) ? $data['identity'] : '');
        $list = $this->getIdentityList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function partner()
    {
        return $this->belongsTo('Partner', 'p_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getMember($id,$field='*'){
        return self::field($field)->where('id',$id)->whereOr('openid',$id)->find();
    }

    //通过会员编号获取用户信息
    public function getMemberBySn($where,$field='*'){
        return self::field($field)->where('membersn','LIKE',"%$where%")->find();
    }




}
